<template>
	<view class="app">
		<view class="item b-b" :class="{ income: item.money > 0 }" v-for="(item, index) in list" :key="index">
			<view class="left column">
				<view class="tit clamp">{{ item.name }}</view>
				<view class="time">{{ item.createdTime }}</view>
			</view>
			<text v-if="item.changeAmount > 0" class="price">+</text>
			<text class="price">{{ item.changeAmount }}</text>
		</view>

		<tui-no-data imgUrl="/static/images/toast/img_nodata.png" v-if="!loading && !list.length">暂无优惠券</tui-no-data>
		<view v-if="!loading && list.length" class="loading-more"><text class="loading-more-text">~~没有更多了~~</text></view>
		<Loading v-if="loading"></Loading>
	</view>
</template>

<script>
import { logListPage } from '@/service/mine.js';
export default {
	data() {
		return {
			params: {
				pageNum: 1,
				pageSize: 10
			},
			loading: true,
			list: []
		};
	},
	onLoad() {
		this.getLog();
	},
	onPullDownRefresh() {
		this.params.pageNum = 1;
		this.getLog();
		setTimeout(v => {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onReachBottom() {
		this.getLog();
	},
	methods: {
		async getLog() {
			try {
				this.loading = true;
				const maps = {
					spinWinAward: '大转盘奖励',
					signIn: '签到',
					signInAward: '签到奖励'
				};
				const resp = await logListPage({ ...this.params, accountType: 'growthValue' });
				resp.data = resp.data.map(v => {
					v.name = maps[v.changeType];
					return v;
				});
				this.list = this.params.pageNum == 1 ? resp.data : [...this.list, ...resp.data];
				this.params.pageNum++;
			} finally {
				this.loading = false;
				//TODO handle the exception
			}
		}
	}
};
</script>

<style scoped lang="scss">
.item {
	display: flex;
	padding: 30rpx 30rpx 30rpx 24rpx;
	background-color: #fff;

	&:after {
		left: 30rpx;
		border-color: #e8e8e8;
	}
	.mix-icon {
		flex-shrink: 0;
		width: 72rpx;
		font-size: 52rpx;
		transform: translateY(-6rpx);
	}
	.icon-tixian1 {
		color: #fd6663;
	}
	.icon-zhangdanmingxi01 {
		color: #ff893a;
	}
	.icon-chongzhi {
		color: #39c585;
	}
	.left {
		margin-left: 20upx;
		flex: 1;
		overflow: hidden;
	}
	.tit {
		font-size: 30rpx;
		color: #333;
		line-height: 1.4;
		margin-bottom: 20rpx;
	}
	.time {
		font-size: 24rpx;
		color: #999;
	}
	.price {
		font-size: 32rpx;
		color: $uni-color-primary;
		font-weight: 700;
	}
	&.income {
		.price {
			color: #00c700;
		}
		.icon-zhangdanmingxi01 {
			color: #39c585;
		}
	}
}
</style>
